
// Lei_visioDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Lei_visio.h"
#include "Lei_visioDlg.h"
#include "Offline.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	enum { IDD = IDD_ABOUTBOX };

	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support

// Implementation
protected:
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()


// CLei_visioDlg dialog




CLei_visioDlg::CLei_visioDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CLei_visioDlg::IDD, pParent)
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CLei_visioDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CLei_visioDlg, CDialog)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	//}}AFX_MSG_MAP
	ON_BN_CLICKED(IDC_BUTTON1, &CLei_visioDlg::OnBnClickedButton1)
	ON_BN_CLICKED(IDOK, &CLei_visioDlg::OnBnClickedOk)
	ON_BN_CLICKED(IDCANCEL, &CLei_visioDlg::OnBnClickedCancel)
	ON_BN_CLICKED(IDC_CHECK1, &CLei_visioDlg::OnBnClickedCheck1)
	ON_BN_CLICKED(IDC_BUTTON2, &CLei_visioDlg::OnBnClickedButton2)
	ON_BN_CLICKED(IDC_BUTTON3, &CLei_visioDlg::OnBnClickedButton3)
	ON_BN_CLICKED(IDC_CHECK3, &CLei_visioDlg::OnBnClickedCheck3)
	ON_BN_CLICKED(IDC_BUTTON4, &CLei_visioDlg::OnBnClickedButton4)
	ON_BN_CLICKED(IDC_BUTTON5, &CLei_visioDlg::OnBnClickedButton5)
	ON_BN_CLICKED(IDC_BUTTON6, &CLei_visioDlg::OnBnClickedButton6)
END_MESSAGE_MAP()


// CLei_visioDlg message handlers

BOOL CLei_visioDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	checked3=false;
	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		BOOL bNameValid;
		CString strAboutMenu;
		bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
		ASSERT(bNameValid);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon

	// TODO: Add extra initialization here

	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CLei_visioDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CLei_visioDlg::OnPaint()
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this function to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CLei_visioDlg::OnQueryDragIcon()
{
	return static_cast<HCURSOR>(m_hIcon);
}


void CLei_visioDlg::OnBnClickedButton1()
{
	//CFileDialog dlg(TRUE, _T("*.bmp"), NULL,OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST|OFN_HIDEREADONLY,_T("image files (*.bmp; *.jpg) |*.bmp;*.jpg|All Files (*.*)|*.*||"),NULL);

	CFileDialog dlg(TRUE,NULL,NULL,OFN_HIDEREADONLY|OFN_FILEMUSTEXIST, 
		"Open video list file(*.txt)|*.txt;||all file(*.*)|*.*");

	dlg.m_ofn.lpstrTitle= _T("Video Feature Extraction"); 

	if (dlg.DoModal() == IDOK) {
		CString path= dlg.GetPathName();  // contain the selected filename
		OfflineExtract(path);// display it
	}
}

void CLei_visioDlg::OnBnClickedOk()
{
	// TODO: Add your control notification handler code here
	cvDestroyAllWindows();
	OnOK();
}

void CLei_visioDlg::OnBnClickedCancel()
{
	// TODO: Add your control notification handler code here
	cvDestroyAllWindows();
	OnCancel();
}

void CLei_visioDlg::OnBnClickedCheck1()
{
	// TODO: Add your control notification handler code here
}

void CLei_visioDlg::OnBnClickedButton2()
{
    CFileDialog dlg(TRUE,NULL,NULL,OFN_HIDEREADONLY|OFN_FILEMUSTEXIST, 
		"Open training feature file(*.xml)|*.xml;||all file(*.*)|*.*");

	dlg.m_ofn.lpstrTitle= _T("Video Feature Quantization"); 

	if (dlg.DoModal() == IDOK) {
		CString path= dlg.GetPathName();  // contain the selected filename
		OfflineQuantz(path);// display it
	}// TODO: Add your control notification handler code here
}

void CLei_visioDlg::OnBnClickedButton3()
{
	CFileDialog dlg(TRUE,NULL,NULL,OFN_HIDEREADONLY|OFN_FILEMUSTEXIST, 
		"Open video feature file(*.xml)|*.xml|Open video list(*.txt)|*.txt||all file(*.*)|*.*");

	dlg.m_ofn.lpstrTitle= _T("Video source indexing and weighting"); 

	if (dlg.DoModal() == IDOK) {
		CString path= dlg.GetPathName();  // contain the selected filename

		CWnd* pWnd=GetDlgItem(IDC_CHECK3);
		if(dlg.GetFileExt()=="xml")
			OfflineIndexingXml(path);// display it
		else if(dlg.GetFileExt()=="txt"){
			if(checked3==true){
				OfflineIndexingTxtSep(path);
			}
			else
			OfflineIndexingTxt(path);
		}
		else
			return;
	}// TODO: Add your control notification handler code here
}
void CLei_visioDlg::OnBnClickedCheck3()
{
	if(checked3 == false)
		checked3 = true;
	else 
		checked3= true;// TODO: Add your control notification handler code here
}

void CLei_visioDlg::OnBnClickedButton4()
{
    CFileDialog dlg(TRUE,NULL,NULL,OFN_HIDEREADONLY|OFN_FILEMUSTEXIST, 
		"Open video list file(*.txt)|*.txt;||all file(*.*)|*.*");

	dlg.m_ofn.lpstrTitle= _T("Video Feature Extraction"); 

	if (dlg.DoModal() == IDOK) {
		CString path= dlg.GetPathName();  // contain the selected filename
		QueryExtract(path);// display it
	}// TODO: Add your control notification handler code here
}

void CLei_visioDlg::OnBnClickedButton5()
{
	CFileDialog dlg(TRUE,NULL,NULL,OFN_HIDEREADONLY|OFN_FILEMUSTEXIST, 
		"Open video list file(*.txt)|*.txt;||all file(*.*)|*.*");

	dlg.m_ofn.lpstrTitle= _T("Video Feature Extraction"); 

	if (dlg.DoModal() == IDOK) {
		CString path= dlg.GetPathName();  // contain the selected filename
		QueryExtract(path);// display it
	}// TODO: Add your control notification handler code here
}

void CLei_visioDlg::OnBnClickedButton6()
{
	CFileDialog dlg(TRUE,NULL,NULL,OFN_HIDEREADONLY|OFN_FILEMUSTEXIST, 
		"Open video list file(*.txt)|*.txt;||all file(*.*)|*.*");

	dlg.m_ofn.lpstrTitle= _T("Video Feature Extraction"); 

	if (dlg.DoModal() == IDOK) {
		CString path= dlg.GetPathName();  // contain the selected filename
		shotExtract(path);// display it
	}
}
